-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEEL variable scope resolution #43
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Upstream fix released, this can be moved further. |
7d79e35
to
b55efe3
Compare
@@ -198,7 +198,7 @@ function getIoExpression(variable, origin) { | |||
return; | |||
} | |||
|
|||
const mapping = mappings.find(mapping => mapping.target === variable.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd apprechiate if we'd group the fix with the actual test that verifies the fix. This way it is easier to understand what we fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix corresponds to
When multiple input or output variables with same name exists within the same process/activity, the later one overwrites all the previous ones.
I'll see if the test case doesn't exist for this, I'll add one. Thanks for pointing this out.
lib/zeebe/VariableResolver.js
Outdated
@@ -59,6 +58,12 @@ export default class ZeebeVariableResolver extends BaseVariableResolver { | |||
// Filter all pre-defined variables | |||
return !namesToFilter.includes(v.name); | |||
}); | |||
|
|||
// keep only unique names | |||
const uniqueVariables = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified in some ways (I think):
// use min-dash uniqueBy utility
const uniqueVariables = uniqueBy('name', filteredVariables.reverse());
const uniqueVariables = Object.values(
filteredVariables.reduce((uniqueVariables, v) => {
uniqueVariables[v.name] = v;
return uniqueVariables;
})
);
Maybe it even makes sense to do the filtering in the previous block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented. The variables are now filtered distinctly using uniqueBy from min-dash
in the base VariableResolver.
@@ -198,7 +198,7 @@ function getIoExpression(variable, origin) { | |||
return; | |||
} | |||
|
|||
const mapping = mappings.find(mapping => mapping.target === variable.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also search mappings from last to first:
mappings.reverse().find(...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason we're sticking to find(...) and avoid filter(...).pop() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find aborts early, while filter goes through the whole list. But in the end it is a matter of taste.
pop()
is also not side-effect free, so it is not fully functional, and may cause (in some situations) issues.
e87fb60
to
6e3dca3
Compare
@@ -198,7 +198,7 @@ function getIoExpression(variable, origin) { | |||
return; | |||
} | |||
|
|||
const mapping = mappings.find(mapping => mapping.target === variable.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find aborts early, while filter goes through the whole list. But in the end it is a matter of taste.
pop()
is also not side-effect free, so it is not fully functional, and may cause (in some situations) issues.
|
||
namesToFilter.push(...outputsToFilter); | ||
} | ||
const namesToFilter = getElementNamesToRemove(moddleElement, inputOutput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with other commit in this PR, what problem does this fix solve? I'd apprechiate if we'd pack implementation + test case together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a fix, just a refactor to clean up the code into a separate function. I'll make sure the commits are clear for reviewers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdul99ahad Thanks for doing this additional round. I still find it a little bit hard to review your PR, because some "FIX" commits still don't contain tests for the actual bugs fixed.
For any reasonably complex topic (such as this one) we need rigid test coverage. I advice you to adopt the practice to pack fix + test into one commit. This helps reviewers to trace what you were doing, and what exactly the expected effect is.
6e3dca3
to
f33b294
Compare
Thanks for pointing this out, Nico. I’ll make sure to include tests alongside fixes in a single commit for better traceability in the future. For now, I’ve separated the refactor into its own commit to keep things clearer. |
Ok, I'll see what I can do, and update this PR with co-location. Will ping you to check back with you, if I grouped things appropriately. |
Prioritize variable resolution as follows: - If both result and output variables exist, prioritize output. - If both result and input variables exist, prioritize result.
f33b294
to
fd86b60
Compare
I have grouped the fixes and tests. 🏅 |
Related to: camunda-modeler #4737
Proposed Changes
List of changes related to scope:
Visual demo
When script result variable and input with same names coexist, result variable overwrites the input variable.
When same name input/output mapping exists, the later one overwrites the previous one.
You can test the implementation by running this command:
npx @bpmn-io/sr bpmn-io/variable-resolver#variable-scoping -l bpmn-io/extract-process-variables#main
Checklist
To ensure you provided everything we need to look at your PR:
@bpmn-io/sr
toolCloses {LINK_TO_ISSUE}
orRelated to {LINK_TO_ISSUE}